package com.education.ai.service.impl;

import com.education.ai.entity.ExamRecord;
import com.education.ai.dao.ExamRecordDao;
import com.education.ai.service.ExamRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

@Service
public class ExamRecordServiceImpl implements ExamRecordService {
    
    private static final Logger logger = LoggerFactory.getLogger(ExamRecordServiceImpl.class);
    
    @Autowired
    private ExamRecordDao examRecordDao;
    
    @Override
    public List<ExamRecord> getExamRecordsByStudentId(String studentId) {
        logger.info("获取学生ID为[{}]的考试记录", studentId);
        return examRecordDao.findByStudentId(studentId);
    }
    
    @Override
    public Map<String, Double> getAverageScoresByStudentId(String studentId) {
        logger.info("计算学生ID为[{}]的平均成绩", studentId);
        return examRecordDao.findAverageScoresByStudentId(studentId);
    }
    
    @Override
    public List<ExamRecord> getExamRecordsByStudentIds(List<String> studentIds) {
        logger.info("批量获取学生ID列表的考试记录，学生数量: {}", studentIds.size());
        return examRecordDao.findByStudentIdIn(studentIds);
    }
    
    @Override
    public ExamRecord saveExamRecord(ExamRecord examRecord) {
        logger.info("保存考试记录: 学生ID[{}], 考试名称[{}]", 
            examRecord.getStudentId(), examRecord.getExamName());
        return examRecordDao.save(examRecord);
    }
    
    @Override
    public List<ExamRecord> saveAllExamRecords(List<ExamRecord> examRecords) {
        logger.info("批量保存考试记录，数量: {}", examRecords.size());
        return examRecordDao.saveAll(examRecords);
    }
} 